package api;

import java.util.HashMap;
import java.util.Map;

import Util.GsonUtils;
import Util.HttpUtil;

public class faceCheck implements IMAGE_TYPE {
	public static String detect(String accessToken, String Base64image, String IMAGE_TYPE) {
		// 请求url
		String url = "https://aip.baidubce.com/rest/2.0/face/v3/detect";
		try {
			Map<String, Object> map = new HashMap<>();
			map.put("image", Base64image);
			map.put("face_field", "faceshape,facetype");
			map.put("image_type", IMAGE_TYPE);

			String param = GsonUtils.toJson(map);

			// 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。

			String result = HttpUtil.post(url, accessToken, "application/json", param);
			System.out.println(result);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
